<template>
	<view>
		<view class="top">
			<view @click="type_qh('运单列表')">
				<p :style="type=='运单列表'?'color: #1890FF;':''">运单列表</p>
				<view class="kkks" :style="type=='运单列表'?'':'border: none;'"></view>
			</view>
			<view @click="type_qh('申请记录')">
				<p :style="type=='申请记录'?'color: #1890FF;':''">申请记录</p>
				<view class="kkks" :style="type=='申请记录'?'':'border: none;'"></view>
			</view>

		</view>
		<view class="wu" v-if="type=='运单列表'&&Waybill_lists_Data.length==0">
			<image src="../../static/wu.png" style="width: 182px; height: 150px; " mode=""></image>
			<p>暂无数据</p>
		</view>
		<!-- 订单列表 -->
		<view class="ddlb" v-if="type=='运单列表'&&Waybill_lists_Data.length!=0">
			<view class="dd" v-for="(time,index) in Waybill_lists_Data" @click="tzxx(time.id+'&all_freight_amount='+time.freight
			+'&all_delivery_amount='+time.all_delivery_amount
			+'&should_advance_amount='+time.should_advance_amount
			+'&all_amount='+time.all_amount
			+'&amount_status='+time.amount_status
			+'&freight='+time.freight
		+'&bond_amount='+time.bond
			)">
				<view class="dd-top">
					<view class="dd-q">
						运单编号：{{time.waybill_sn}}
					</view>
					<view class="dd-p">
						查看详情
					</view>
				</view>

				<view class="dd-dd">
					<!-- 是否垫资 0 未垫资 1=垫资 -->
					<p>是否垫付：{{time.is_advance==0?'未垫资':'垫资'}}</p>
					<p>运费：{{time.freight}}</p>
					<!-- 是否需要配送 0不需要 1=需要 -->
					<p>是否送货：{{time.is_delivery==0?'不需要':'需要'}}</p>
					<p>保证金：{{time.bond}}</p>
					<p>应垫资金额：{{time.should_advance_amount}}</p>
					<p>额外增加费用：{{time.freight_again_amount}}</p>
				</view>
				<!-- <button  type="primary"  @click.stop="fareApplyHande(time)">申请车费</button> -->
				<view class="dd-btn-box">
					<button size="mini" type="primary" @click.stop="fareAddApply(time)">增加车费</button>
					<button size="mini" type="primary" @click.stop="fareApplyHande(time)">申请车费</button>
				</view>
			</view>

			<!-- <button v-if="Waybill_lists_Data.length!=0">申请车费</button> -->
		</view>





		<view class="wu" v-if="type=='申请记录'&&Freight_lists_Data.length==0">
				<image src="../../static/wu.png" style="width: 182px; height: 150px; " mode=""></image>
				<p>暂无数据</p>
			</view>
		<view class="ddlb" v-if="type=='申请记录'&&Freight_lists_Data.length!=0" style="width: 100%;">
			
			<view class="dd" style="width: 100%;border-radius: 0px; padding-top: 5px; padding-bottom:15px;"
				v-for="(time,index) in Freight_lists_Data">
				<view class="dd-dd">
					<p style="width:100%;">运单编号：{{time.waybill_sn}}</p>
					<p style="font-size: 14px;">金额：{{time.all_mount}}</p>
					<p style="font-size: 14px;">申请时间：{{time.createtime}}</p>
				</view>
				<!-- 已通过  申请中  已拒绝 -->
				<!-- 申请状态:1=审核中,2=已拒绝,3=已打款 status -->
				<button :style="
				time.status==1?'border-radius: 4px;color: #fff;width: 90%;background: #1890FF;':
				time.status==2?'border-radius: 4px;color: #fff;width: 90%;background: #FF3838;':
				time.status==3?'border-radius: 4px;color: #fff;width: 90%;background: #0ACF00;':''
				">
					{{
					time.status==1?"审核中":
					time.status==2?"已拒绝":
					time.status==3?"已通过":""
				}}</button>
			</view>

		</view>
		<!-- 增加车费申请 -->
		<view class="tc" v-if="showIncreaseFare">
			<fare-apply-item @tocancel="tocancelHande" @toconfirm="toconfirmHande"></fare-apply-item>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//运单列表  申请记录
				type: "运单列表",
				Waybill_lists_Data: [],
				Freight_lists_Data: [],
				page: 1,
				showIncreaseFare: false,
				fareAddApplyWaybillId: 0,
			}
		},
		onLoad() {
			// this.Freight_lists();
			this.page =1
			// this.Waybill_lists();
		},
		onShow() {
			this.getOrderConfirmFlag();
		},
		onReachBottom() {
			console.log('this.type: ', this.type);
			let x = this.type;
			this.page++;
			if(x=="申请记录")
			{
				this.Freight_lists();
			}
			
			if(x=="运单列表")
			{
				this.Waybill_lists();
			}
			
		},
		methods: {
			//申请记录
			jiLuXiangQing()
			{
				
			},
			//申请车费 申请记录
			Freight_lists() {
				//0=不分状态运单列表，1=申请运费运单列表，2=申请保证金运单列表
				let data = {
					waybill_sn: "",
					page: this.page,
				}
				this.$rqt.Freight_lists(data).then(res => {
					console.log(res);
					let data = res.data.data;
					this.Freight_lists_Data = [...this.Freight_lists_Data, ...data]; 
					// this.Freight_lists_Data = data; 
				})
			},
			type_qh(x) {
				this.page = 1;
				this.type = x;
				if(x=="申请记录")
				{
					this.Freight_lists_Data = [];
					this.Freight_lists();//保证金申请记录
				}
				
				if(x=="运单列表")
				{
					this.Waybill_lists_Data = [];
					this.Waybill_lists();//运单列表
				}
			},
			tzxx(x) {
				uni.navigateTo({
					url: "/pages/shenqingchefei/shenqingchefei_a?id=" + x
				});
			},
			//运单列表
			Waybill_lists() {
				//0=不分状态运单列表，1=申请运费运单列表，2=申请保证金运单列表
				let data = {
					type: "1",
					page: this.page,
				}
				this.$rqt.Waybill_lists(data).then(res => {
					console.log(res);
					let data = res.data.data;
					// this.Waybill_lists_Data = data;
					this.Waybill_lists_Data = [...this.Waybill_lists_Data, ...data];
					
				})
			},
			 
			fareApplyHande(e)
			{
				console.log('fareApplyHandee: ',e);
				let {id,freight} = e;
				uni.navigateTo({
					url: "/pages/my/a_xuanzezhanghu?id="+id+"&bond_amount="+freight+"&name=chefei"
				});
			},
			fareAddApply(e){
				console.log('e: ',e);
				let {id} = e;
				this.fareAddApplyWaybillId = id;
				 this.showIncreaseFare = true;
			},
			tocancelHande(e){
				this.showIncreaseFare = false;
			},
			toconfirmHande(e){
				this.showIncreaseFare = false;
				this.addFreightAmount(e);
			},
			addFreightAmount(e){
				let data = {
					waybill_id: this.fareAddApplyWaybillId,
					amount: e.amount,
					remark: e.remark,
				}
				console.log('data: ',data);
				
				this.$rqt.freightaddAmount(data).then(res => {
					let {msg} = res;
					uni.showToast({
						title: msg
					})
					
					 
				})
			},
			getOrderConfirmFlag(){
				const value = uni.getStorageSync('OrderConfirmFlag');
				console.log('getOrderConfirmFlag', value);
				if (value && value == '1') {
					this.type_qh('运单列表');
				}
			}
		}
	}
</script>

<style scoped>
	.wu {
		width: 100%;
		text-align: center;
		padding-top: 60px;
		color: #999999;
		font-size: 18px;
		line-height: 40px;
	}

	.top {
		display: flex;
		height: 52px;
		justify-content: space-around;
		background-color: #fff;
	}

	.top>view {
		width: 100%;
		font-size: 15px;
		font-weight: 600;
		/* color: #1890FF; */
		line-height: 50px;
		height: 50px;
		text-align: center;
	}

	.top>view>p {
		height: 50px;
	}

	.kkks {
		clear: both;
		width: 60px;
		margin: 0 auto;
		/* background-color: #1890FF; */
		border-bottom: 2px #1890FF solid;
	}

	/* 订单列表 */
	.ddlb {
		padding-bottom: 20px;
		width: 95%;
		margin: 0 auto;
	}

	.ddlb>button {
		margin-top: 20px;
		width: 100%;
		height: 50px;
		box-shadow: 0px 0px 4px 0px rgba(204, 204, 204, 0.5);
		border-radius: 8px;
		color: #fff;
		/* background: #1890FF; */
		background: #999999;
	}

	.dd {
		margin-top: 12px;
		width: 100%;
		padding-bottom: 10px;
		background: #FFFFFF;
		box-shadow: 0px 0px 6px 0px rgba(204, 204, 204, 0.5);
		border-radius: 8px;
	}

	.dd-top {
		width: 100%;
		display: flex;
		justify-content: space-between;
		border-bottom: 1px dashed #CCCCCC;
	}

	.dd-q {
		font-size: 18px;
		font-weight: 500;
		margin-left: 20px;
		line-height: 50px;

	}

	.dd-p {
		font-size: 18px;
		color: #1890FF;
		line-height: 50px;
		margin-right: 20px;
	}

	.dd-dd {
		overflow: hidden;
		width: 90%;
		margin: 0 auto;
	}

	.dd-dd>p {
		line-height: 40px;
		float: left;
		width: 50%;
		font-size: 16px;
		font-weight: 400;
	}
	.dd-btn-box{
		display: flex;
	}
	.tc {
		position: fixed;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		background: rgba(0, 0, 0, 0.2);
	}
</style>

<style>
	page {
		background: #F7F7F7;
	}
</style>
